
#include "Device_MFK.h"


#define kNumOfMFKDevices	2
#define kMaxNumOfMFKInputChars	16

extern char *inputString;

typedef struct {
	bool valid;
	SFScreenId screenId;
	MFKInputEnded endCallback;
	char inputString[kMaxNumOfMFKInputChars];
}MFKHandle;

static MFKHandle m_handles[kNumOfMFKDevices] = {
	{.valid = FALSE,},
	{.valid = FALSE,},
};


extern SFCode MFKStartInput(SFScreenId screenId, const char *message, MFKInputEnded endCallback){
	MFKHandle *handle = &m_handles[screenId/2];
	
	if((handle->valid)&&((handle->endCallback)!=NULL)){
		handle->endCallback(handle->screenId);
	}
	handle->valid = TRUE;
	handle->screenId = screenId;
	handle->endCallback = endCallback;
	
	/* TODO: manipulate with the MFK */

	return SFCodeOK;
}

extern SFCode MFKEndInput(SFScreenId screenId){
	MFKHandle *handle = &m_handles[screenId/2];
	
	if((handle->screenId) == screenId){
		handle->valid = FALSE;
	}

	return SFCodeOK;
}

extern SFCode MFKReadInputString(SFScreenId screenId, const char **cString, SFInputStringMode *mode){
	int deviceId = screenId/2;
	MFKHandle *handle = &(m_handles[deviceId]);

	if(!(handle->valid)){
		return SFCodeNoData;
	}
	
	if(inputString == NULL){
		return SFCodeNoData;
	}
	
	*cString = inputString;
	
	inputString = NULL;
	
	return SFCodeOK;
}

